package igeomap.domain;

import igeomap.controller.ControllerScattaFoto;
import igeomap.foundation.CreateFotoHolder;


import java.io.File;
import java.io.IOException;

import android.hardware.Camera;
import android.location.Location;
import android.util.Log;
import android.view.SurfaceHolder;

public class Fotocamera {
	private static Fotocamera fotocamera;
    private static CreateFotoHolder createFotoHolder;
	private static Camera mCamera=null;
	private static Camera.Parameters parameters;
	public Fotocamera()
	{
		
		InizializzaCamera();
		parameters=mCamera.getParameters();
		
		SetCameraParameters();
	}
	public static Fotocamera getFotocameraIstance()
	{
		if(fotocamera==null)
		{
			fotocamera=new Fotocamera();
		
		}
		return fotocamera;
	}

	public void SetCameraParameters()
	{
		mCamera.setParameters(parameters);
	}
	public void InizializzaCamera()
	{
		if(mCamera!=null)
			RilasciaCamera();
			
	    try {
	    	
	    	mCamera = Camera.open(); // attempt to get a Camera instance
	    }
	    catch (Exception e){
	        // Camera is not available (in use or does not exist)
	    }
	   
		
	}
	public Camera.Parameters getCameraParameters()
	{
	return mCamera.getParameters();
	}
	public void StopPreview()
	{
	mCamera.stopPreview();
	}
	public void StartPreview()
	{
	mCamera.startPreview();
	}
	public void RilasciaCamera()
	{
	
	mCamera.release();
	
	}
	
	public void SetGPSData(double latitude,double longitude,double altitude,long timestamp)
	{
		parameters.setGpsAltitude(altitude);
		parameters.setGpsTimestamp(timestamp);
		parameters.setGpsLatitude(latitude);
		parameters.setGpsLongitude(longitude);
	}
	public void SetPreviewDisplay(SurfaceHolder mHolder) 
	{
		try 
        {
            mCamera.setPreviewDisplay(mHolder);
            
        } 
        catch (Exception e)
        {
         //   Log.d(VIEW_LOG_TAG, "Errore: " + e.getMessage());
        }
	
	}
	public void takePicture() 
	{
		// TODO Auto-generated method stub
		createFotoHolder=CreateFotoHolder.getCreateFotoHolderIstance();
		mCamera.takePicture(null, null, createFotoHolder);
		
	}

	
	
}
